<?php

function view_pelanggan($config,$param) {
    view_header_up($config,$param);
    //
    ?><title>Idebeda-Pelanggan</title><?
    //
    view_header_bottom($config,$param);
    ?>
    <h2>Daftar Pelanggan</h2>
    <script type="text/javascript">
		function showHide(id){
			$('#'+id).toggle('slow');
		}
		function cariPelanggan(page){
			var key = document.getElementById('qword').value;
			var msg = document.getElementById('cpelanggan-val');
			
			xmlhttp=mintajax();
			xmlhttp.onreadystatechange=function()
			{
			  if (xmlhttp.readyState== 4 && xmlhttp.status== 200)
			  {
				//alert('Ditemukan');
				msg.innerHTML = xmlhttp.responseText;
			  }
			}
			xmlhttp.open("GET","<? echo $config['home_url']."pelanggan/id/cari"; ?>?qword="+key+"&off="+page,true);
			xmlhttp.send(null);
		}
		$(document).ready(function () {
			cariPelanggan('1');
		});
	</script>
    <?
    if (isset($_SESSION['succ'])) {
        echo '<div class="success alert">'.$_SESSION['succ'].'</div>';
        unset($_SESSION['succ']);
    }
    $off = isset($_GET['off']) ? ((intval($_GET['off']) > 0) ? intval($_GET['off']) : 1) : 1;
    ?>
    <div onclick="showHide('cpelanggan-val')"><h4>Cari Pelanggan</h4></div>
	<div id="cpelanggan">
		<ul>
			<li class="field">
				<input class="narrow text input" id="qword" name="qword" type="text" placeholder="keywords" >
				<span class="medium primary btn icon-right icon-search" onclick="cariPelanggan('1')">Cari</span>
			</li>
		</ul>
		<div id="cpelanggan-val"></div>
	</div>
<?
	view_footer($config,$param);
}

function view_pelangganid($config,$param,$id) {
    view_header_up($config,$param);
    //
    ?><title>Idebeda-Pelanggan</title><?
    //
    view_header_bottom($config,$param);
    ?>
    <h2>Pelanggan</h2>
    <script type="text/javascript">
		function validateEmpty(fld) {
			var error = "";
		 
			if (fld.value.length == 0) {
				fld.style.background = 'Yellow'; 
				error = "1";
			} else {
				fld.style.background = 'White';
			}
			return error;  
		}
		function validateForm(theForm) {
			var reason = "";
			
			  reason += validateEmpty(theForm.nama);
			  reason += validateEmpty(theForm.nohp);
			  reason += validateEmpty(theForm.kota);
			  reason += validateEmpty(theForm.prov);
			  reason += validateEmpty(theForm.pobox);
			  reason += validateEmpty(theForm.lengkap);
				  
			  if (reason != "") {
				alert("Perhatian, isi yang masih kosong.");
				return false;
			  }

			  return true;
		}
	</script>
    <?
    if (isset($_SESSION['succ'])) {
        echo '<div class="success alert">'.$_SESSION['succ'].'</div>';
        unset($_SESSION['succ']);
    }
    $db =  new db($config);
	$result = $db->query("SELECT * FROM mn_customer WHERE idCustomer = '".urlencode($id)."'");
    ?>
    <form action="" id="fpelanggan" method="post" onsubmit="return validateForm(this)">
		<ul>
			<input name="idcust" type="hidden" value="<? echo $id; ?>" />
			<li class="field">
				<label class="inline" for="nama">Nama</label>
				<input class="wide text input" id="nama" name="nama" type="text" placeholder="nama pelanggan" value="<? echo $result[0]['nama']; ?>" />
			</li>
			<li class="prepend field">
				<label class="inline" for="nohp">Nomor HP</label>
				<span class="adjoined">+62</span>
				<input class="narrow text input" id="nohp" name="nohp" type="text" placeholder="nomor handphone" value="<? echo $result[0]['no_hape']; ?>" />
			</li>
			<li class="field">
				<label class="inline" for="prov">Provinsi</label>
				<input class="normal text input" id="prov" name="prov" type="text" placeholder="prov" value="<? echo $result[0]['prov']; ?>" />
			</li>
			<li class="field">
				<label class="inline" for="kota">Kota</label>
				<input class="normal text input" id="kota" name="kota" type="text" placeholder="kota" value="<? echo $result[0]['kabkot']; ?>" />
			</li>
			<li class="field">
				<label class="inline" for="pobox">Kodepos</label>
				<input class="xnarrow text input" id="pobox" name="pobox" type="text" placeholder="kodepos" value="<? echo $result[0]['kodepos']; ?>" />
			</li>
			<li class="field">
				<label class="inline" for="lengkap">Alamat</label>
				<textarea class="input textarea" rows="3" placeholder="Alamat lengkap" name="lengkap" id="lengkap"><? echo $result[0]['alamat']; ?></textarea>
			</li>
			<li class="prepend field">
				<label class="inline" for="fb">FB</label>
				<span class="adjoined">facebook.com/</span>
				<input class="normal text input" id="fb" name="fb" type="text" placeholder="akun fb" value="<? echo $result[0]['fb']; ?>" />
			</li>
			<li class="prepend field">
				<label class="inline" for="tw">Twitter</label>
				<span class="adjoined">@</span>
				<input class="narrow text input" id="tw" name="tw" type="text" placeholder="akun twitter" value="<? echo $result[0]['twitter']; ?>" />
			</li>
			<div class="medium primary btn"><input type="submit" name="ubah" value="Ubah" /></div>
			</div>
		</ul>
	</form>
<?
	view_footer($config,$param);
}

?>
